<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval( getvar( "gametype" ) );
$chkGametype = chkGametype( $gametype );
$chk = new CheckMode_3d( $curruser['acl'], 1, $gametype );
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
$g_betname_3or5 = judge_type( $gametype );
unset( $chk );
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
$ui = new UI_3D( true );
$tpl = new Template2();
$conf = new Config();
if ( isset( $_SESSION['subaccount'] ) )
{
    $ui->showErrorPage( "你是子帐号，不能执行这个功能！" );
    exit();
}
$order = getvar( "order" );
$split = getvar( "split" );
$disk = getvar( "disk" );
$ratemod = getvar( "ratemod" );
$playtype = getvar( "playtype" );
$lotto_id_3d = getvar( "lotto_id" );
$bid = getvar( "bid" );
$listnum = getvar( "listnum" );
$slicetype = getvar( "slicetype" );
$bnowAcl = getvar( "bnowAcl" );
if ( $lotto_id_3d == "" )
{
    echo "{\"errormsg\":\"no data\"}";
    exit();
}
else if ( $lotto_id_3d != 0 )
{
    $lotto_id_3d = intval( $lotto_id_3d );
}
if ( $chkGametype == 3 )
{
    require_once( "class_5h/RateConfig_5h.php" );
    require_once( "class_5h/BetTotal_5h.php" );
    require_once( "class_5h/Bet_5h.php" );
    $RateConfig_3d = new RateConfig_5h( $gametype );
    $BetTotal_3d = new BetTotal_5h( $lotto_id_3d, $gametype );
    $_5hFlag = true;
    $_8hFlag = false;
    $_5hFlag = false;
    $_8hFlag = true;
}
elseif ( $chkGametype == 4 )
{
    require_once( "class_sb/RateConfig_sb.php" );
    require_once( "class_sb/BetTotal_sb.php" );
    require_once( "class_sb/Bet_sb.php" );
    $RateConfig_3d = new RateConfig_sb( $gametype );
    $BetTotal_3d = new BetTotal_sb( $lotto_id_3d, $gametype );
    $_5hFlag = false;
    $_8hFlag = false;
    $_5hFlag = false;
    $_8hFlag = false;
}
else
{
    require_once( "class_3d/RateConfig_3d.php" );
    require_once( "class_3d/BetTotal_3d.php" );
    require_once( "class_3d/Bet_3d.php" );
    $RateConfig_3d = new RateConfig_3d( $gametype );
    $BetTotal_3d = new BetTotal_3d( $lotto_id_3d, $gametype );
    $_5hFlag = false;
    $_8hFlag = false;
}
$split = isset( $RateConfig_3d->splitArr[$split] ) ? $split : "1";
$disk = isset( $RateConfig_3d->diskArr[$disk] ) ? $disk : 0;
$order = isset( $RateConfig_3d->orderArr[$order] ) ? $order : 0;
$ratemod = isset( $RateConfig_3d->ratemodArr[$ratemod] ) ? $ratemod : 2;
$playtype = isset( $RateConfig_3d->playtypeArr02[$playtype] ) ? $playtype : "r1";
$listnum = $listnum == "" ? 0 : intval( $listnum );
$slicetype = $slicetype == "" ? 0 : intval( $slicetype );
$time = systime( ) - 30;
if ( $disk == 0 )
{
    $diskStr = "";
}
else
{
    $diskStr = $RateConfig_3d->diskArr[$disk];
}
$sObj = NULL;
$rateArr = NULL;
$tempStr = "";
if ( $bid != "" && in_array( $bid, $RateConfig_3d->playGroupArr02[$playtype] ) )
{
    $playArr = array( 0 => $bid );
}
else
{
    $playArr = $RateConfig_3d->playGroupArr02[$playtype];
}
$i = 0;
$companyFlag = true;
if ( $curruser['acl'] == 255 )
{
    $showid = "0";
    $companyFlag = false;
}
else
{
    $showid = $curruser['id'];
    $companyFlag = true;
}
$allDataNum = 0;
$allDataAmount = 0;
$openDate = date( "Y-m-d" );
$rs = getdb( "SELECT open FROM lotto_{$tbl} WHERE id = {$lotto_id_3d} LIMIT 1" );
if ( !$rs->eof )
{
    $openDate = $rs->f[0];
}
$rs->close();
$postTime = $conf->get( "paper_post_bet" );
$today = date( "Hi" ) <= $postTime ? date( "Y-m-d", strtotime( "-1 day" ) ) : date( "Y-m-d" );
if ( $_5hFlag || $_8hFlag )
{
    if ( $openDate == $today )
    {
        $Bet_3d = new Bet_5h( $gametype );
    }
    else
    {
        $Bet_3d = new Bet_5h( $gametype, "x" );
    }
    if ( $_8hFlag )
    {
        $getAllBetArr = array( "10", "11", "12", "13", "14", "15", "16", "17" );
    }
    else
    {
        $getAllBetArr = array( "9", "10", "11", "12", "13", "14" );
    }
    $getDiffTotalBettypesArr = array();
}
elseif ( $chkGametype == 4 )
{
	if ( $openDate == $today )
    {
        $Bet_3d = new Bet_sb( $gametype );
    }
    else
    {
        $Bet_3d = new Bet_sb( $gametype, "x" );
    }
    $getAllBetArr=array();
    $getDiffTotalBettypesArr = array();	
}
else
{
    if ( $openDate == $today )
    {
        $Bet_3d = new Bet_3d( $gametype );
    }
    else
    {
        $Bet_3d = new Bet_3d( $gametype, "x" );
    }
    $getAllBetArr = array( "35", "46" );
    $getDiffTotalBettypesArr = array( "g3", "g6", "rcmp", "r1pass", "all" );
}
$showids = $Bet_3d->getMyMemberIdByAcl( $curruser['id'], $curruser['acl'] );
$tbdList = "";
$tempStrTotal = "{\"rdata\":[";
foreach ( $g_betname_3or5 as $key => $val )
{
    $bettypeArr = explode( "_", $key );

    if ( in_array( $bettypeArr[0], $getAllBetArr ) )
    {
        $tempDataTotal = $Bet_3d->getDataListTotal( $lotto_id_3d, $key, $curruser['acl'], $showids, $split, $diskStr );
    }
    else
    {
        $tempDataTotal = $BetTotal_3d->getDataListTotal( $lotto_id_3d, $key, $showid, $split, $diskStr );
    }
    if ( $tempDataTotal != false )
    {
        $dataTotal = intval( $tempDataTotal['totalnum'] );
        $dataAmount = round( $tempDataTotal['amount'] );
        $databack2 = intval( $tempDataTotal['back2'] );
        $databack1 = round( $tempDataTotal['back1'] );
        if ( $cutData = $RateConfig_3d->chkG3G6Idx( $bettypeArr[0] ) )
        {
            $dataTotal = $dataTotal / $cutData;
            $dataAmount = $dataAmount / $cutData;
            $databack2 = $databack2 / $cutData;
            $databack1 = $databack1 / $cutData;
        }
        $allDataNum += $dataTotal;
        $allDataAmount += $dataAmount;
    }
    else
    {
        $dataTotal = "0";
        $dataAmount = "0";
        $databack2 = "0";
        $databack1 = "0";
    }
    if ( $time < $tempDataTotal['updatetime'] )
    {
        $bgclass = "namount";
    }
    else
    {
        $bgclass = "";
    }
    $tbdList .= "<tr align=\"right\">"."<td class=\"bgClc_{$gametype}\">{$val}</td>"."<td class=\"td2\">{$dataTotal}</td>"."<td class=\"td2 span3da {$bgclass}\" onClick=\"javascript:link({$bettypeArr[0]},".(empty($bettypeArr[1])?0:$bettypeArr[1]).");\">{$dataAmount}</td></tr>";
}
$tbdList .= "<tr align=\"right\">"."<td class=\"bgClc_{$gametype}\">合计</td>"."<td class=\"td2\">{$allDataNum}</td>"."<td class=\"td2\">{$allDataAmount}</td></tr>";

foreach ( $RateConfig_3d->playtypeArr02 as $key => $val )
{
    $bettypeTemp = implode( ",", $RateConfig_3d->playGroupArr02[$key] );
    if ( in_array( $key, $getDiffTotalBettypesArr ) )
    {
        $speStr = implode( ",", $RateConfig_3d->playGroupArr02[$key] );
        $tempDataTotal = $Bet_3d->getDataListTotal( $lotto_id_3d, $speStr, $curruser['acl'], $showids, $split, $diskStr, $speStr, $key == "all" );
    }
    else
    {
        $tempDataTotal = $BetTotal_3d->getDataListTotalForBettypeS( $lotto_id_3d, $bettypeTemp, $showid, $split, $diskStr );
    }
}
$list = "";
$list .= "<option value=0";
if ( $split == 0 )
{
    $list .= " selected";
}
$list .= ">全部<option value=1";
if ( $split == 1 )
{
    $list .= " selected";
}
$list .= ">成数</select>";
$disks = "";
$disks .= "<option value=0".( $disk == 0 ? " selected" : "" ).">全部";
$disks .= "<option value=1".( $disk == 1 ? " selected" : "" ).">A 盘";
$disks .= "<option value=2".( $disk == 2 ? " selected" : "" ).">B 盘";
$disks .= "<option value=3".( $disk == 3 ? " selected" : "" ).">C 盘";
$disks .= "<option value=3".( $disk == 4 ? " selected" : "" ).">D 盘";
$disks .= "</select>";
$tpl->load( "main", "onlinebet_3d_all.htm" );
$tpl->set( array( "tbdList" => $tbdList, "gametype" => $gametype, "dataTotal" => $dataTotal, "lotto_id_3d" => $lotto_id_3d, "list" => $list, "disks" => $disks, "gametype_name" => $tblName, "openDate" => $openDate ) );
$ui->header();
$tpl->show( "main" );
$ui->footer();
?>